package com.zhuoshi.converter;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;
public class DateConverter implements Converter<String,Date> {
	@Override
	public Date convert(String source) {
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    //设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期，比如2007/02/29会被接受，并转换成2007/03/01
	        sdf.setLenient(false);
	        try {
	            return sdf.parse(source);
	        } catch (Exception e) {
	            System.out.println(e);
	        }
	        return null;
	    }
	}
